package {
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import global.Global;
	
	import worlds.BaseWorld;
	
	[SWF(backgroundColor="#ffffff", frameRate="25", width="1024", height="768", fullScreen="true")]
	public class DiningOrder extends Sprite
	{
		private var _urlRequest				: URLRequest = new URLRequest();
		private var _loader					: Loader = new Loader();
		private var _urlLoader					: URLLoader = new URLLoader();
		
		public function DiningOrder()
		{
			setFullScreen();
			loadConfirm();
		}
		private function setFullScreen():void {
			try {
				stage.displayState = StageDisplayState.FULL_SCREEN;
			} catch(error:Error) {}
		}
		private function loadConfirm():void {
			_urlLoader.addEventListener(Event.COMPLETE, loadConfirmCompleteHandler);
			_urlRequest.url = "configs/config.xml";
			_urlLoader.load(_urlRequest);
		}
		private function loadConfirmCompleteHandler(event:Event):void {
			_urlLoader.removeEventListener(Event.COMPLETE, loadConfirmCompleteHandler);
			Global.config = new XML(_urlLoader.data);
			loadResources();
		}
		private function loadResources():void {
			_urlRequest.url = "Assets.swf";
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadResourcesCompleteHandler);
			_loader.load(_urlRequest);
		}
		private function loadResourcesCompleteHandler(event:Event):void {
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadResourcesCompleteHandler);
			Global.resource = _loader.content;
			start();
		}
		/**
		 *
		 * 加载完成，开始初始化软件其他部分 
		 * 
		 */		
		private function start():void {
			// 该客户端不允许修改菜单布局
			Global.recipeMakePermitted = false;
			// 初始化并加载MainWorld
			var world:BaseWorld = BaseWorld.getInstance();
			addChild(world);
			world.init();
		}
	}
}